declare module "vm" {
  namespace Types {
    namespace Xhr {
      interface Progress extends CM_Types.Xhr.Progress {
        readonly context: AnyRecord | undefined;
      }
      interface Response extends CM_Types.Xhr.Response {
        readonly context: AnyRecord | undefined;
      }
      interface Details extends CM_Types.Xhr.Details {
        anonymous?: boolean;
        context?: AnyRecord;
        data?:
          | string
          | Blob
          | File
          | Record<string | number, unknown>
          | Array<unknown>
          | FormData
          | URLSearchParams;
        responseType?: XMLHttpRequestResponseType;
        url: string | URL;
        onabort?: (e: Response) => void;
        onerror?: (e: Response) => void;
        onload?: (e: Progress) => void;
        onloadend?: (e: Progress) => void;
        onloadstart?: (e: Progress) => void;
        onprogress?: (e: Progress) => void;
        onreadystatechange?: (e: Response) => void;
        ontimeout?: (e: Progress) => void;
      }
    }
    namespace Download {
      interface Context {
        readonly name?: string;
        readonly onload?: (e: Response) => void;
      }
      interface Progress extends Omit<CM_Types.Xhr.Progress, "context"> {
        readonly context: Context;
      }
      interface Response extends Omit<CM_Types.Xhr.Response, "context"> {
        readonly context: Context;
      }
      interface Details {
        anonymous?: boolean;
        context?: AnyRecord;
        headers?: Parameters<typeof browser.downloads.download>[0]["headers"];
        name?: Parameters<typeof browser.downloads.download>[0]["filename"];
        password?: string;
        timeout?: number;
        url: Parameters<typeof browser.downloads.download>[0]["url"];
        user?: string;
        onabort?: (e: Response) => void;
        onerror?: (e: Response) => void;
        onload?: (e: Progress) => void;
        onloadend?: (e: Progress) => void;
        onloadstart?: (e: Progress) => void;
        onprogress?: (e: Progress) => void;
        onreadystatechange?: (e: Response) => void;
        ontimeout?: (e: Progress) => void;
      }
    }
    namespace Notification {
      interface Option extends CM_Types.Notification.Option {
        silent?: boolean;
        onclick?: (this: Option) => void;
        ondone?: (this: Option) => void;
        tag?: string;
        zombieTimeout?: number;
        zombieUrl?: string;
      }
      interface Return {
        remove(): Promise<null>;
      }
    }
    namespace Vcl {
      type cbFunction = (
        name: string,
        oldValue: unknown,
        newValue: unknown,
        remote: boolean,
      ) => void;
    }
    namespace OpenTab {
      interface Option {
        active?: boolean;
        container?: number;
        insert?: boolean;
        pinned?: boolean;
      }
      interface Result {
        close(): void;
        readonly closed: boolean;
        onclose: (this: Result) => void | null;
      }
    }
    interface Resource {
      readonly name: string;
      readonly url: string;
    }
    namespace Menu {
      interface Options {
        id?: string;
        autoClose?: boolean;
        title?: string;
      }
    }
  }
}
